package com.yixq.soa.service.auth;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

//import com.fasterxml.classmate.TypeResolver;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@Profile({"dev","prod"})
public class SwaggerConfig {
	static Logger log = LoggerFactory.getLogger(SwaggerConfig.class);
	
	

	@Bean
    public Docket createRestApi() {
		log.info("初始化swagger.");
		//TypeResolver resolver = new TypeResolver();

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yixq.soa.service.auth.controller"))
                .paths(PathSelectors.any())
                .build()
                //.alternateTypeRules(AlternateTypeRules.newRule(LocalDate.class, String.class))
                //.directModelSubstitute(LocalDate.class, LocalDateTModel.class)
                .directModelSubstitute(LocalDate.class, Date.class)
                .directModelSubstitute(LocalDateTime.class, Date.class)
                .directModelSubstitute(LocalTime.class, Date.class)
                //.additionalModels(new LocalDateResolvedType())
                //.securityContexts(securityContexts());
                ;
    }
	
//	private List<SecurityContext> securityContexts(){
//		
//		return null;
//	}

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("伴生活商圈管理平台")
                .description("伴生活商圈管理平台的接口说明")
                .termsOfServiceUrl("http://banshenghuo.com/")
                .contact(new Contact("伴生活", "http://banshenghuo.com/",null))
                .version("0.0.1")
                .build();
    }
}
